import { BaseResultType } from '#/request'
import useDealResult from '@/hooks/dealResult'
import uniRequest from '@/request'

const { dealResult, checkResult } = useDealResult()

export const getDeviceCounterDetails = async (id = '', networkPointId = ''): Promise<BaseResultType<any> | null> => {
  let path = '/sh/api/getDeviceCounterDetails?'
  if (networkPointId) {
    path = `${path}networkPointId=${networkPointId}`
  } else {
    path = `${path}userId=${id}`
  }
  const [result, err] = await uniRequest.get(path)
  return Promise.resolve(dealResult(err, result))
}
export const getDeviceCabinetDetails = async (counterNo: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/sh/api/getDeviceCabinetDetails?counterNo=' + counterNo)
  return Promise.resolve(dealResult(err, result))
}

export const getCabinetStatus = async (): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/sh/api/getCabinetStatus')
  return Promise.resolve(dealResult(err, result))
}

export const unlockAll = async (deviceId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/sh/api/unlockAll?deviceId=' + deviceId)
  return Promise.resolve(dealResult(err, result))
}
export const unlock = async (cabinetId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/sh/api/unlock?cabinetId=' + cabinetId)
  return Promise.resolve(dealResult(err, result))
}
export const selectStatus = async (cabinetId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/sh/api/selectStatus?cabinetId=' + cabinetId)
  return Promise.resolve(dealResult(err, result))
}
export const setCabinetStatus = async (cabinetId: string, status: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/sh/api/setCabinetStatus?cabinetId=' + cabinetId + '&status=' + status)
  return Promise.resolve(dealResult(err, result))
}
